import java.util.HashMap;
import java.util.Map;

public class Solution {
    public int longestSubsequence(int[] arr, int difference) {
        Map<Integer,Integer> map = new HashMap<Integer,Integer>();
        int ret = 1;
        for (int a : arr) {
            map.put(a, map.getOrDefault(a - difference, 0) + 1);
            ret = Math.max(ret, map.get(a));
        }

        return ret;
    }
}
